var express = require('express');
var router = express.Router();
const Base = require('../dao/com_base_dao');


/**
 * 获取机构或者基金且筹码集中的持仓数量,不包含风险和退市股
 * 机构信息在 股东表中
 */
router.get('/jj/centralize/list/:offset/:limit', async function (req, res) {
    const offset = req.params.offset
    const limit = req.params.limit
    const resData = {
        code: 0, msg: 'success', offset: parseInt(offset), data: []
    }
    resData.data = await Base.findListCentralize(parseInt(offset), parseInt(limit))
    res.json(resData).end();
});
/**
 * 获取风险股列表,
 * 传递分页
 */
router.get('/list/risk/:offset/:limit/:stock_code*?', async function (req, res) {
    const offset = req.params.offset
    const limit = req.params.limit
    const stock_code = req.params.stock_code
    const resData = {
        code: 0, msg: 'success', offset: parseInt(offset), data: []
    }
    let riskData = await Base.findListRisk(stock_code, parseInt(offset), parseInt(limit))
    resData.data = riskData.rows
    resData.count = riskData.count
    res.json(resData).end();
});

router.post('/tc/:offset/:limit', async function (req, res, next) {
    const offset = req.params.offset
    const limit = req.params.limit
    const board_name = req.body.board_name
    const users = await Base.findAllByBoardName(offset, limit, board_name)
    const resData = {
        code: 0, msg: 'success', offset: parseInt(offset), count: users.count, data: users.rows
    }
    res.send(resData);
});
router.get('/one/:stock_code', async function (req, res, next) {
    const stock_code = req.params.stock_code
    const users = await Base.findOne(stock_code)
    const resData = {
        code: 0, msg: 'success', data: users
    }
    res.send(resData);
});

module.exports = router;
